package utils

import (
	"gitcode.com/G-YT/baoyou/server/global"
	"time"
)

func ResetExpiredTargetPlans() {
	now := time.Now()
	loc := now.Location()
	dayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc)
	dayEnd := dayStart.Add(24 * time.Hour)
	// 公益服务到期重置
	global.GVA_DB.Model(&struct{}{}).Exec("UPDATE by_target_plan SET pro_bono_num=0, pro_bono_start_time=?, pro_bono_end_time=?, pro_bono_status=2 WHERE pro_bono_end_time >= ? AND pro_bono_end_time < ?", time.Time{}, time.Time{}, dayStart, dayEnd)
	// 新增会员到期重置
	global.GVA_DB.Model(&struct{}{}).Exec("UPDATE by_target_plan SET incr_vip_num=0, incr_vip_start_time=?, incr_vip_end_time=?, incr_vip_status=2 WHERE incr_vip_end_time >= ? AND incr_vip_end_time < ?", time.Time{}, time.Time{}, dayStart, dayEnd)
	// 服务会员到期重置
	global.GVA_DB.Model(&struct{}{}).Exec("UPDATE by_target_plan SET service_vip_num=0, service_vip_start_time=?, service_vip_end_time=?, service_vip_status=2 WHERE service_vip_end_time >= ? AND service_vip_end_time < ?", time.Time{}, time.Time{}, dayStart, dayEnd)
}
